package com.zmn.oms.orderwork;

import com.github.ltsopensource.spring.boot.annotation.EnableJobClient;
import com.zmn.base.channel.dubbo.interfaces.channel.ChannelListRemoteService;
import com.zmn.common.utils.math.MathUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.manager.mq.annotation.EnableMQSend;
import com.zmn.oms.business.interfaces.perf.PerfCityBService;
import com.zmn.oms.business.interfaces.warranty.OrderWarrantyBService;
import com.zmn.oms.model.dto.work.masterwork.CompleteDTO;
import com.zmn.oms.model.entity.callrecord.OrderCallRecord;
import com.zmn.oms.model.entity.perf.PerfCity;
import com.zmn.oms.services.interfaces.callrecord.OrderCallRecordService;
import com.zmn.oms.zmn.business.interfaces.work.masterwork.ZsMasterWorkBService;
import org.apache.dubbo.config.annotation.Reference;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.List;


@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)

@SpringBootApplication(scanBasePackages = "com.zmn", exclude = RabbitAutoConfiguration.class)
@EnableJobClient
@EnableMQSend
@EnableTransactionManagement
public class OrderWarrantyTests2 {

    @Autowired
    private OrderWarrantyBService orderWarrantyBService;

    @Autowired
    private ZsMasterWorkBService zsMasterWorkBService;

    @Reference(version = com.zmn.base.plat.engine.common.constant.DubboConsts.INTERFACE_VERSION , check = false)
    protected ChannelListRemoteService channelListRemoteService;

    @Autowired
    private PerfCityBService perfCityBService;

    @Autowired
    private OrderCallRecordService orderCallRecordService;

    @BeforeClass
    public static void init() {
        System.setProperty("es.set.netty.runtime.available.processors", "false");
    }

//    @Test
//    public void testChannelProductRemote() {
//        com.zmn.common.dto2.ResponseDTO<ChannelProductDRO> channelProductDROResponseDTO = channelListRemoteService.getByServAndChannelAndPlatIdDIO(1273, 2, 1001);
//        ChannelProductDRO channelProductDRO = channelProductDROResponseDTO.getData();
//
//        int channelAmount = 0;
//        if (channelProductDROResponseDTO.isSuccess() && channelProductDRO != null && channelProductDRO.getCommission() != null) {
//            Double commission = channelProductDRO.getCommission();
//            // 比例返佣
//            if (Objects.equals(channelProductDRO.getCommissionType(), 1)) {
//                channelAmount = Double.valueOf(MathUtil.mul(120, commission)).intValue();
//            }
//            // 固定金额返佣
//            else if (Objects.equals(channelProductDRO.getCommissionType(), 2)) {
//                channelAmount = commission.intValue();
//            }
//        }
//
//        System.out.println(channelAmount);
//    }

    @Test
    public void testCrmUser() {

    }

    @Test
    public void testActiveWarranty() {
        Long orderId = 289146648628965376L;
        orderWarrantyBService.activeWarranty(orderId);
    }

    @Test
    public void testCompleteOrder() throws Exception {
        CompleteDTO completeDTO = new CompleteDTO();
        completeDTO.setOrderId(295960225440477184L);
        completeDTO.setWorkId(295960225440477184L);
        completeDTO.setOperatorType(3);
        completeDTO.setOperatorId(131981L);
        completeDTO.setOperator("1风测试");
        completeDTO.setLongitude(29.560893D);
        completeDTO.setLatitude(106.640746D);
        zsMasterWorkBService.completeOrder(completeDTO);
    }

    @Test
    public void perfCity() {
        List<PerfCity> perfCitys = perfCityBService.queryStatisticsList("2019-02-01", "2019-02-15");
        System.out.println("asfasf");
    }

    public static void main(String[] args) {

        double rate = MathUtil.div(8, 100,2);
        Integer channelAmount =(int)MathUtil.mul(120,rate);

        if (NumberUtil.isPositiveInteger(1584) || NumberUtil.isPositiveInteger(1002) || NumberUtil.isPositiveInteger(2)) {
            System.out.println("--------------------222");
        }
    }

    @Test
    public void testcall() {

        OrderCallRecord orderCallRecord = new OrderCallRecord();
        orderCallRecord.setOrderId(499906038871371776L);
        orderCallRecordService.insertOrderCallRecord(orderCallRecord);
    }


}
